project(CpeManager VERSION 0.1 LANGUAGES CXX)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)

file(GLOB PROJECT_SOURCES *.cpp *.rc)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(CpeManager
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
    set_property(TARGET CpeManager APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
                ${CMAKE_CURRENT_SOURCE_DIR}/android)
else()
    if(ANDROID)
        add_library(CpeManager SHARED
            ${PROJECT_SOURCES}
        )
        set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(CpeManager
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(CpeManager PRIVATE
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Network
    CpePluginManager
)

target_include_directories(CpeManager PRIVATE
    ../CpePluginManager
)

target_link_directories(CpeManager PUBLIC
	${CMAKE_BINARY_DIR}/lib
)

set_target_properties(CpeManager PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
    DEBUG_POSTFIX "d"
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(CpeManager)
endif()

IF(WIN32)
    # 去除命令提示框
    SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
ENDIF()
